package com.qingxin.jcdw.service;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;
import com.qingxin.jcdw.entity.Jcdw;
import com.qingxin.sys.dao.Querier;
import com.qingxin.sys.dao.Updater;
import com.qingxin.sys.entity.LoginUser;
import com.qingxin.sys.mvc.PageParam;
import com.qingxin.sys.mvc.Pager;
import com.qingxin.sys.mvc.SysError;
import com.qingxin.sys.service.BaseService;
import com.qingxin.sys.utils.BeanUtil;
@Service
public class JcdwService extends BaseService<Jcdw, String>{
	
	/**
	 * 列表数据
	 * @param pageParam
	 * @param search
	 * @param request
	 * @return
	 */
	public Pager list(PageParam pageParam,String search, HttpServletRequest request){
		Querier querier = Querier.create("from Jcdw");
		Pager pager = pageByQuerier(querier, pageParam);
		return pager;
	}
	
	/**
	 * 添加
	 * @param jcdw
	 * @param loginUser
	 * @param request
	 * @return
	 */
	public SysError add(Jcdw jcdw, LoginUser loginUser, HttpServletRequest request){
		this.save(jcdw);
		return null;
	}
	
	/**
	 * 删除
	 * @param ids
	 * @param request
	 * @return
	 */
	public SysError delete(String[] ids,HttpServletRequest request){
		for(String id : ids){
			Jcdw jcdw = this.get(id);
			if(jcdw == null){
				continue;
			}
			this.delete(jcdw);
		}
		return null;
	}
	
	/**
	 * 更新数据
	 * @param jcdw
	 * @param loginUser
	 * @param request
	 * @return
	 */
	public SysError update(Jcdw jcdw,LoginUser loginUser, HttpServletRequest request){
		Jcdw old = getSafeEntity(jcdw.getJcdwid());
		String fields = "jcdwname,responsible,address,phone";
		BeanUtil.setTargetFields(old, jcdw, fields, true);
		Updater<Jcdw> updater = new Updater<>(old, fields);
		this.update(updater);		
		return null;
	}
	
}
